package com.showsu.editor.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.showsu.editor.dao.TblSysDictMapper;
import com.showsu.editor.entity.doo.SysDict;
import com.showsu.editor.entity.po.TblSysDict;
import com.showsu.editor.enums.DeleteStatusEnum;
import com.showsu.editor.service.ISysDictService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author kevin
 * @since 2021-07-24
 */
@Service
public class SysDictServiceImpl extends ServiceImpl<TblSysDictMapper, TblSysDict> implements ISysDictService {

    @Autowired
    private TblSysDictMapper tblSysDictMapper;

    @Override
    public SysDict queryByAppIdAndKey(String appId, String dictKey) {
        if (StringUtils.isBlank(appId) || StringUtils.isBlank(dictKey)) {
            return null;
        }
        TblSysDict tblSysDict = tblSysDictMapper.selectOne(new QueryWrapper<TblSysDict>().lambda()
                .eq(TblSysDict::getDictKey, dictKey)
                .eq(TblSysDict::getAppId, appId)
                .eq(TblSysDict::getIsDelete, DeleteStatusEnum.Normal.getCode())
                .last("order by id desc limit 1"));
        return tblSysDict == null ? null : BeanUtil.copyProperties(tblSysDict, SysDict.class);
    }
}
